package afcp.alumni.file;

import java.nio.charset.Charset;
import java.util.List;

import afcp.alumni.model.db.FileColumn;
import afcp.alumni.util.Charsets;

public class CsvFile implements AlumniFile {
	
	private static final Charset DEFAULT_CHARSET = Charsets.CP1252;
	
	private String charset;
	private char separator = CSVParser.DEFAULT_SEPARATOR;
	private char quote = CSVParser.DEFAULT_QUOTE_CHARACTER;
	private char escape = CSVParser.DEFAULT_ESCAPE_CHARACTER;
	private List<FileColumn> headers;
	
	public CsvFile() {
	}
	
//	public CsvFile(String charset, char separator, char quote, char escape,
//			Map<String, String> headers) {
//		super();
//		this.charset = charset;
//		this.separator = separator;
//		this.quote = quote;
//		this.escape = escape;
//		this.headers = headers;
//	}

	public String getCharset() {
		return charset;
	}
	public Charset getCharsetObj() {
		try {
			return Charset.forName(charset);
		} catch (Exception e1) {
			return DEFAULT_CHARSET;
		}
	}
	public void setCharset(String charset) {
		this.charset = charset;
	}
	public char getSeparator() {
		return separator;
	}
	public void setSeparator(char separator) {
		this.separator = separator;
	}
	public char getQuote() {
		return quote;
	}
	public void setQuote(char quote) {
		this.quote = quote;
	}
	public char getEscape() {
		return escape;
	}
	public void setEscape(char escape) {
		this.escape = escape;
	}
	public List<FileColumn> getHeaders() {
		return headers;
	}
	public void setHeaders(List<FileColumn> headers) {
		this.headers = headers;
	}
	
	@Override
	public void trimHeaders() {
		for (FileColumn column : headers) {
			column.setLabel(column.getLabel().trim());
		}
//		for (Entry<String, String> entry : headers.entrySet()) {
//			entry.setValue(entry.getValue().trim());
//		}
	}

//	@Deprecated
//	@Override
//	public FileReader toFileReader(InputStream inputStream)
//			throws IncorrectHeaderException, IOException {
//		return new CSVReader(new InputStreamReader(inputStream, this.getCharsetObj()),
//				separator, quote, escape);
////		return new MemberReader(inputStream, this);
//	}

}
